package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysDiagnosisRecord;
import com.ruoyi.system.service.ISysDiagnosisRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 诊断结果列Controller
 * 
 * @author ruoyi
 * @date 2022-06-07
 */
@RestController
@RequestMapping("/system/diagnosisrecord")
public class SysDiagnosisRecordController extends BaseController
{
    @Autowired
    private ISysDiagnosisRecordService sysDiagnosisRecordService;

    /**
     * 查询诊断结果列列表
     */
   // @PreAuthorize("@ss.hasPermi('system:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysDiagnosisRecord sysDiagnosisRecord)
    {
        startPage();
        List<SysDiagnosisRecord> list = sysDiagnosisRecordService.selectSysDiagnosisRecordList(sysDiagnosisRecord);
        return getDataTable(list);
    }

    /**
     * 导出诊断结果列列表
     */
   // @PreAuthorize("@ss.hasPermi('system:record:export')")
    @Log(title = "诊断结果列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysDiagnosisRecord sysDiagnosisRecord)
    {
        List<SysDiagnosisRecord> list = sysDiagnosisRecordService.selectSysDiagnosisRecordList(sysDiagnosisRecord);
        ExcelUtil<SysDiagnosisRecord> util = new ExcelUtil<SysDiagnosisRecord>(SysDiagnosisRecord.class);
        util.exportExcel(response, list, "诊断结果列数据");
    }

    /**
     * 获取诊断结果列详细信息
     */
   // @PreAuthorize("@ss.hasPermi('system:record:query')")
    @GetMapping(value = "/{companyId}")
    public AjaxResult getInfo(@PathVariable("companyId") Long companyId)
    {
        return AjaxResult.success(sysDiagnosisRecordService.selectSysDiagnosisRecordByCompanyId(companyId));
    }

    /**
     * 新增诊断结果列
     */
  //  @PreAuthorize("@ss.hasPermi('system:record:add')")
    @Log(title = "诊断结果列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysDiagnosisRecord sysDiagnosisRecord)
    {
        SysDiagnosisRecord query=new SysDiagnosisRecord();
        query.setCompanyId(sysDiagnosisRecord.getCompanyId());
        query.setNaireId(sysDiagnosisRecord.getNaireId());
        query.setDomainId(sysDiagnosisRecord.getDomainId());
        List<SysDiagnosisRecord> list = sysDiagnosisRecordService.selectSysDiagnosisRecordList(query);
        if(list!=null&&list.size()>0){
            sysDiagnosisRecord.setUpdateBy(getUsername());
            return toAjax(sysDiagnosisRecordService.updateSysDiagnosisRecord(sysDiagnosisRecord));
        }
        sysDiagnosisRecord.setCreateBy(getUsername());
        return toAjax(sysDiagnosisRecordService.insertSysDiagnosisRecord(sysDiagnosisRecord));
    }

    /**
     * 修改诊断结果列
     */
   // @PreAuthorize("@ss.hasPermi('system:record:edit')")
    @Log(title = "诊断结果列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDiagnosisRecord sysDiagnosisRecord)
    {
        return toAjax(sysDiagnosisRecordService.updateSysDiagnosisRecord(sysDiagnosisRecord));
    }

    /**
     * 删除诊断结果列
     */
   // @PreAuthorize("@ss.hasPermi('system:record:remove')")
    @Log(title = "诊断结果列", businessType = BusinessType.DELETE)
	@DeleteMapping("/{companyIds}")
    public AjaxResult remove(@PathVariable Long[] companyIds)
    {
        return toAjax(sysDiagnosisRecordService.deleteSysDiagnosisRecordByCompanyIds(companyIds));
    }
}
